package com.common.model.response;
import com.common.model.enums.ErrorCode;
import java.io.Serializable;


/**
 * JSON返回对象
 * @ClassName: JsonResponse  
 * @Description: TODO(这里用一句话描述这个类的作用)  
 * @author "Linfeng Han"  
 * @date 2017年1月5日 上午10:03:06
 *  
 * @param <T>
 */
public class JsonResponse<T> implements Serializable {

	private static final long serialVersionUID = 3005454862247116787L;

	// 返回码
	private String code;

	// 返回信息
	private String msg;

	// 返回内容
	private T body;

	/**
	 * 成功
	 */
	public JsonResponse() {
		this.code = ErrorCode.SUCCESS.getCode();
		this.msg = ErrorCode.SUCCESS.getMsg();
		this.body = null;
	}

	/**
	 * 成功
	 */
	public JsonResponse(T body) {
		this.code = ErrorCode.SUCCESS.getCode();
		this.msg = ErrorCode.SUCCESS.getMsg();
		this.body = body;
	}

	/**
	 * 失败
	 */
	public JsonResponse(ErrorCode errorCode) {
		this.code = errorCode.getCode();
		this.msg = errorCode.getMsg();
		this.body = null;
	}

	/**
	 * 失败
	 */
	public JsonResponse(ErrorCode errorCode, T body) {
		this.code = errorCode.getCode();
		this.msg = errorCode.getMsg();
		this.body = body;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getBody() {
		return body;
	}

	public void setBody(T body) {
		this.body = body;
	}
}